/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import modelo.Historial;
import dao.generic.GenericDAO;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Administrador
 */
public class HistorialDAO extends GenericDAO {

    public Historial getHistorialbyId(int idHistorial) {
        Historial h = null;
        try {
            iniciarOperacion();
            h = (Historial) sesion.get(Historial.class, idHistorial);

        } finally {
            sesion.close();
        }
        return h;
    }
    
    public Historial getHistorialbyFechaDn(Date fecha,int nd) {
        Historial h = null;
        try {
            iniciarOperacion();
            Criteria criteria = sesion.createCriteria(Historial.class)
                    .add(Restrictions.eq("fecha", fecha))
                    .add(Restrictions.eq("diaNoche", nd));
            
            h = (Historial) criteria.uniqueResult();

        } finally {
            sesion.close();
        }
        return h;
    }
    
    

    public List consultaTodo() {
        List listaHis;
        try {
            iniciarOperacion();
            Query query = sesion.createQuery("FROM Historial");
            listaHis = query.list();
        } finally {
            sesion.close();
        }
        return listaHis;
    }
    public Historial ultimoRegistro(){
        Historial ultimo;
        try {
            iniciarOperacion();
            Query query = sesion.createQuery("FROM Historial where id in (SELECT MAX(id) FROM Historial)");
            ultimo = (Historial)query.uniqueResult();
            
        } finally {
            sesion.close();
        }
        return ultimo;
    }
    public void consultaGasto(){
      Iterator i;
      try{
        iniciarOperacion();
        Query query = sesion.createQuery("SELECT s.");
        
      }catch(HibernateException e){
        manejarExcepcion(e);
      }
    }
}
